/**
 * @author fengchao
 */
$(function() {

	function loginClass() {
		this.myID = "";
		this.msg = "程序正在执行，请稍后！";
		this.uname = "";
		this.pwd = "";
		this.ajaxurl = "http://222.41.30.48:8888/sxhck/sx_admin/admin_login/";
		//登录框居中
		this.setcenter = function() {
			$(this.myID).css({
				top : ($(document).height() - $(this.myID).height()) / 2 + 'px',
				left : ($(document).width() - $(this.myID).width()) / 2 + 'px'
			});
		}
		//清除登录框中的数据
		this.resetval = function() {
			$("#sx_login_b_reset a").click(function() {
				$(".sx_login_input_value input").val("");
			});
			//添加loading效果
			this.sxLoading = function() {
				$("body").append("<div id='sxlodingbody'><span class='sxlodingbody_img'><img src='images/loading.gif' width=30></span><span class='sxlodingbody_value'>" + this.msg + "</span></div>");
			}
			//删除loading效果
			this.sxLoadingclose = function() {
				$('#sxlodingbody').remove();
			}
			//用户提交数据
			this.sxloginsubmit = function() {
				if(this.uname == "" || this.pwd == "") {
					this.msg = "用户名密码不能为空!";
					this.sxLoading();
				} else {
					
					this.msg = "程序正在执行，请稍后......!";
  					this.sxLoading();					
					$.ajax({
						type : "POST",
						url : this.ajaxurl,
						data : "user="+this.uname+"&pwd="+this.pwd,
						dataType:'json',
						success : function(msg) {
							$('#sxlodingbody').remove();
							alert(msg.Msg);
						}
					});
				}
			}
		}
	}

	var login = new loginClass();
	login.myID = "#sx_login_body";
	login.setcenter();

	login.resetval();
	//点击登录按钮执行事件
	$("#sx_login_b_submit").click(function() {
		login.uname = $("#sx_login_unamevalue").val();
		login.pwd = $("#sx_login_upwdevalue").val();
		login.sxloginsubmit();
	});
});
